using System;
using Xunit;

namespace CodePlex.TfsLibrary.ObjectModel.DataObjects
{
    public class SourceItemTest
    {
        [Fact]
        public void CaseInsensitive()
        {
            SourceItem item1 = new SourceItem();
            item1.LocalName = @"C:\Foo\bar1.txt";

            SourceItem item2 = new SourceItem();
            item2.LocalName = @"C:\fOo\BaR1.tXt";

            Assert.Equal(0, ((IComparable<SourceItem>)item1).CompareTo(item2));
            Assert.Equal(0, ((IComparable<SourceItem>)item2).CompareTo(item1));
        }

        [Fact]
        public void IdenticalItems()
        {
            SourceItem item = new SourceItem();
            item.LocalName = @"C:\Foo\bar.txt";

            Assert.Equal(0, ((IComparable<SourceItem>)item).CompareTo(item));
        }

        [Fact]
        public void LocalNameFirst()
        {
            SourceItem item1 = new SourceItem();
            item1.LocalName = @"C:\Foo\bar1.txt";
            item1.RemoteName = "$/Foo/bar2.txt";

            SourceItem item2 = new SourceItem();
            item2.LocalName = @"C:\Foo\bar2.txt";
            item2.RemoteName = "$/Foo/bar1.txt";

            Assert.True(((IComparable<SourceItem>)item1).CompareTo(item2) < 0);
            Assert.True(((IComparable<SourceItem>)item2).CompareTo(item1) > 0);
        }

        [Fact]
        public void RemoteItemStatusDeleteBeforeAddForItemsWithTheSameName()
        {
            SourceItem item1 = new SourceItem();
            item1.LocalName = @"C:\Foo\bar1.txt";
            item1.RemoteItemStatus = SourceItemStatus.Delete;

            SourceItem item2 = new SourceItem();
            item2.LocalName = @"C:\Foo\bar1.txt";
            item2.RemoteItemStatus = SourceItemStatus.Add;

            Assert.True(((IComparable<SourceItem>)item1).CompareTo(item2) < 0);
            Assert.True(((IComparable<SourceItem>)item2).CompareTo(item1) > 0);
        }

        [Fact]
        public void RemoteNameSecond()
        {
            SourceItem item1 = new SourceItem();
            item1.LocalName = null;
            item1.RemoteName = "$/Foo/bar1.txt";

            SourceItem item2 = new SourceItem();
            item2.LocalName = null;
            item2.RemoteName = "$/Foo/bar2.txt";

            Assert.True(((IComparable<SourceItem>)item1).CompareTo(item2) < 0);
            Assert.True(((IComparable<SourceItem>)item2).CompareTo(item1) > 0);
        }
    }
}